package com.wl.controller;

import java.io.IOException;

import com.wl.service.CommentService;
import com.wl.service.NewsService;
import com.wl.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>Title: IndexController.java</p>
 * <p>Description: TODO</p>
 * <p>CreateDate: 2017年6月14日</p>
 *
 * @author shen
 * @version v1.0
 */
@RequestMapping("/src/main/test")
@Controller
public class TestController {

    private final static Logger LOG = Logger.getLogger(TestController.class);

    @Autowired
    UserService service;

    @Autowired
    CommentService commentService;

    @Autowired
    NewsService newsService;

    @RequestMapping("/jsp")
    public String ssm(Model model) {
        LOG.info("---视图测试---");
        model.addAttribute("data", "很抱歉，只做了一点微小的工作。");
        return "view";
    }

    @RequestMapping("/login")
    public String login(Model model) {
        return "login";
    }

    @ResponseBody
    @RequestMapping("/userList")
    public Object testForm() throws IllegalStateException, IOException {
        return service.userList();
    }

    @RequestMapping("/commentList")
    public Object testComment(@RequestParam Integer page,
                              @RequestParam Integer pageSize,
                              @RequestParam String content,
                              @RequestParam(required = false) Long userId
    ) throws IllegalStateException, IOException {
        return commentService.commentList(page, pageSize, null, content);
    }

    @RequestMapping("/newsList")
    public Object testNewsList(@RequestParam Integer page,
                               @RequestParam Integer pageSize,
                               @RequestParam String title,
                               @RequestParam String status
    ) throws IllegalStateException, IOException {
        return newsService.newsInfoList(page, pageSize, title, status);
    }


}
